package com.derbysoft.defender.controller;

import com.derbysoft.defender.api.AccessTokenHolder;
import com.derbysoft.defender.api.requester.UserRequester;
import com.derbysoft.defender.api.response.OAuth2AccessToken;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>some description here.</p>
 * Created by Afee Lee on 2017-03-26 13:32
 *
 * @author Afee Lee
 * @version 1.0
 * @see Object
 * @since 1.8
 */
@RestController
@RequestMapping("/wechat")
public class WeChatController extends AbstractController {
    public static final String URL_USER_LIST = "/wechat/mp/user/list";
    public static final String URL_TOKEN = "/oauth/token?grant_type=client_credentials";

    @PostMapping(value = "/user/list")
    public Object getUserList(String clientId, String clientSecret) {
        OAuth2AccessToken accessToken = AccessTokenHolder.getAccessToken(authUrlPrefix + URL_TOKEN, clientId, clientSecret);
        UserRequester userRequester = new UserRequester(accessToken.getAccess_token());
        return userRequester.listUsers(resourceUrlPrefix + URL_USER_LIST);
    }
}
